#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

/*
 * @param sum1 加数, 必须保证最后一个字符串以0结尾;
 * @param sum2 被加数, 同样必须保证最后一个字符串必须以0结尾;
 * @return 返回只为指向结果的字符串;
 */

const char* sum(const char *sum1, const char* sum2){

     if(sum1 == NULL )
         return sum2;
     if(sum2 == NULL )
         return sum1;
     int n1 = strlen(sum1);
     int n2 = strlen(sum2);
     int n = n1>n2?n1:n2;
     char *result = (char*)malloc(n+2);
     int temp = 0;
     int jinwei = 0 ;
    int i  = 0;
     while(n1>0 && n2 >0){
        temp = sum1[--n1] + sum2[--n2] + jinwei - '0';
        if(temp > '9'){
            jinwei = 1;
            temp = temp -10;
        }else{
            jinwei = 0;
        }
        result[i++] = temp;
     }
     while(n1>0){
         temp = sum1[--n1] + jinwei;
         if(temp > '9' ){
            temp = temp - 10;
            jinwei = 1;
         }
         else{
            jinwei = 0;
         }
         result[i++] = temp ;
     }
     while(n2>0){
         temp = sum1[--n2] + jinwei;
         if(temp > '9' ){
            temp = temp - 10;
            jinwei = 1;
         }
         else{
            jinwei = 0;
         }
         result[i++] = temp ;
     }
     if(jinwei == 1){
         result[i++] = jinwei+'0';
     }
    result[i] = 0;
    int j = strlen(result)-1;
     for(int k = 0; k <=(strlen(result)-1)/2 ; k++,j--){
         temp  = result[k] ;
         result[k] = result[j];
         result[j] = temp;
     }
     return result;

}


